Skip to content

ingest_stored deletes its own refused, unregistered object - #554

Merged
fazpu merged 5 commits into
mainfrom
feat/ingest-stored-discard-refused
Nov 7, 2026
Merged

fazpu merged 5 commits into
mainfrom
feat/ingest-stored-discard-refused

Conversation

@fazpu

@fazpu fazpu commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

UMC needs this for large direct uploads (UMC #804). When ingest_stored refuses an object, UMC can't tell whether the key is already registered, so refused uploads of up to 5 GiB would stay in storage unbilled. Per the team-lead's decision, the engine now deletes its own refused, unregistered object.

  • Refusals: any refusal from ingest_stored now raises StoredObjectRefusedError(refusal=..., raw_object_deleted=...), a ValueError that carries the original error. That covers:
    • a declared-size mismatch;
    • a content-type refusal (ContentDetectionError);
    • a managed-metering refusal (ManagedTextClassificationError);
    • a forgotten identity (ForgottenSourceError);
    • invalid metadata.
  • What is deleted: the engine deletes the object, unless a content keeps the key as its raw object (DocumentCatalog.raw_object_registered, an EXISTS lookup on content_objects.raw_uri). A refused replay of a registered key keeps its object. raw_object_deleted says which happened.
  • Other failures delete nothing: storage or database errors, and admission paused for a forget in progress (ForgetInProgressError), raise unchanged, so a retry can succeed. A key outside uploads/ is still a plain ValueError and deletes nothing.
  • Sweeper: public UploadIngestor.discard_unregistered(*, deployment_id, key) -> bool applies the same rule on its own, for UMC's sweeper of uploads abandoned before registration (unregistered bytes escape hard forget).
    • If a content keeps the key, it keeps the object and returns False.
    • Otherwise it deletes the object and returns True; a missing object also returns True.
    • A key outside uploads/ raises ValueError.
    • ingest_stored's refusal path uses it.
  • Concurrency: the caller must not register the same key concurrently. The registration check and the delete are not one transaction.
  • Compatibility (Action needed for callers): ingest_stored shipped in v0.18.2 with the original refusal types. A caller that catches ContentDetectionError, ManagedTextClassificationError or ForgottenSourceError from it must now catch StoredObjectRefusedError and inspect .refusal. A caller catching ValueError keeps working. UMC (#804) is the only known caller and has been told. The engine is pre-1.0.
  • Docs: D147, the docstrings and a new "Unreleased" changelog section are updated; the type change is marked Action needed.
  • Streaming: reading the object stays outside the refusal handler. A storage failure deletes nothing, even one raised as ValueError (such as a malformed Content-Length).

Test plan

  • ruff, pyright, unit lane (3154 passed)

  • test_ingest_routability.py::test_a_storage_failure_while_streaming_deletes_nothing

  • test_ingest_stored_pg.py::test_a_refused_object_is_deleted_unless_a_content_keeps_it: a refused new key is deleted, and a refused replay of a registered key is kept. Also covers discard_unregistered: an abandoned object is deleted, a missing one counts as success, a registered one is kept, and a key outside uploads/ is refused.

  • test_managed_metering_sql.py: the metering refusal (source_bytes_limit_exceeded) wraps the original error and deletes the object.

  • The PostgreSQL tests run in CI; local containers are off-limits.

  • I have read and agree to the RememberStack Contributor License Agreement v1.0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm

@fazpu fazpu changed the title Discard a refused stored object unless a content keeps it ingest_stored deletes its own refused, unregistered object Nov 7, 2026
@fazpu

fazpu commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Codex review, round 1 (gpt-6.1-sol, max), on the earlier design (discard_unregistered)

VERDICT: APPROVE

No blocker, major, or minor findings.

  • content_objects.raw_uri covers registered objects, including managed-metering staged/pending rows and soft-deleted content.
  • Hard forget records the original key in its durable manifest before scrubbing raw_uri; concurrent discard remains safe and idempotent.
  • The namespace check matches ingest_stored. Documented per-key serialization is sufficient because other ingest paths cannot introduce an uploads/ reference.
  • Tests cover retention, deletion, missing-object success, and namespace rejection. D147, docstrings, and changelog agree. Reuse identities and paid processing are unaffected.

Validation: 16 related unit tests passed; CI quality passed. PostgreSQL integration CI was pending. No containers started or files modified.

Design change (commit 6225dd0)

The team-lead decided that ingest_stored deletes its own refused, unregistered object and reports it, rather than exposing a separate method. A refusal now raises StoredObjectRefusedError(refusal, raw_object_deleted); the public discard_unregistered is removed. Codex round 2 reviews this.

@fazpu
fazpu force-pushed the feat/ingest-stored-discard-refused branch from 6225dd0 to 9b9ce0f Compare November 7, 2026 15:50
@fazpu

fazpu commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Codex review, round 2 (gpt-6.1-sol, max)

VERDICT: REQUEST_CHANGES

  1. Major — e0.py:462: storage failures can delete valid uploads. The broad ValueError handler also covers streaming. Reproduced using the MinIO adapter and botocore StreamingBody: a malformed Content-Length raises ValueError, which becomes StoredObjectRefusedError(raw_object_deleted=True) and purges valid bytes. A retry then gets FileNotFoundError; restoring the same bytes succeeds. Simplest fix: move streaming outside the refusal handler and limit destructive handling to refusal/validation operations. Add this regression test.

  2. Minor — changelog/page.mdx:57: the release premise is false. v0.18.2 is published and contains ingest_stored with the original exception types. The new wrapper bypasses callers catching those types, while this entry incorrectly attributes it to that release. Simplest fix: document the change under the upcoming release, mark the exception-handling migration Action needed, and correct the PR’s compatibility claim.

Otherwise, expected refusals are covered. raw_uri protects registered objects, including pending metering and soft-deleted rows. Hard-forget ordering, exact-key purge, error reporting, and documented per-key serialization are sound. Reuse identities and paid work are unaffected.

Validation: 163 related local tests passed; CI quality/unit passed, worker database tests remained pending. No files modified or containers started.

Dispositions (commit 9b9ce0f, rebased on main)

  1. Fixed. Streaming (iter_bytes, hashing and the spool write) now runs before the refusal handler. Only the size check, admission, detection, metering and record_upload are inside it (two try blocks, through _refused). A storage failure raises unchanged and deletes nothing. Regression test: test_a_storage_failure_while_streaming_deletes_nothing (a stream that yields a chunk and then raises ValueError as a malformed Content-Length would; asserts a plain ValueError and nothing purged).
  2. Fixed. I removed the line from the already published 0.18.2 changelog; the 0.18.3 release prep writes the entry, with the suggested Action needed text now in the PR body. The PR's compatibility note is corrected: callers catching the original types must catch StoredObjectRefusedError and inspect .refusal. The only known caller, UMC #804, has been told.

@fazpu

fazpu commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Round 3 of the Codex review was stopped before it finished. The team-lead and UMC asked to keep a public UploadIngestor.discard_unregistered(*, deployment_id, key) -> bool for UMC's sweeper of abandoned uploads, alongside ingest_stored's own delete-on-refusal; ingest_stored's refusal path now calls it (commit dca26b0). The changelog now has an "Unreleased" section with the Action needed entry. Codex round 3 is re-running on this commit.

@fazpu

fazpu commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Codex review, round 3 (gpt-6.1-sol, max)

VERDICT: APPROVE

No blocker, major, or minor findings at dca26b065.

  • Round-2 fixes verified. Streaming runs outside the refusal handlers, and its regression test passes. The Unreleased changelog correctly marks the exception migration Action needed.
  • Refusal handling: e0.py:398 covers size, content-type, managed-metering, metadata-validation and forgotten-source refusals. No remaining retryable-failure misclassification or missed supported refusal found. Database/storage failures and ForgetInProgressError propagate.
  • Registered-object safety: document_catalog.py:383 checks content_objects.raw_uri, including pending metering and soft-deleted content. Hard-forget ordering preserves safety.
  • Public sweeper: e0.py:488 enforces the upload namespace, purges only the exact key, handles absence idempotently, and documents per-key serialization.
  • Reporting and compatibility: the wrapper retains the original refusal and reports deletion accurately. D147, docstrings and changelog agree. The v0.18.2 compatibility change is explicitly acknowledged. Rule 4 reuse identities and paid processing remain unaffected.

Validation: 168 local tests passed, Ruff and diff checks passed. CI quality/unit passed; database integration remained pending at last check. No files modified or containers started.

fazpu and others added 5 commits November 7, 2026 17:03
A host whose ingest_stored call was refused cannot tell whether the key
is already some content's raw object (a refused re-registration of a
registered key). discard_unregistered deletes the object only when no
content keeps it, and returns whether it did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Team-lead decision: instead of a separate discard method, a refusal
(size, content type, metering, forgotten identity, invalid metadata)
raises StoredObjectRefusedError(refusal, raw_object_deleted). The engine
deletes the refused object unless a content keeps the key as its raw
object. Storage and database failures delete nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Streaming the object runs outside the refusal handler, so a read failure
(even one raised as ValueError, like a malformed Content-Length) deletes
nothing and can be retried. The changelog line moves out of the already
published 0.18.2; the 0.18.3 release prep carries it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Team-lead and UMC: a public UploadIngestor.discard_unregistered deletes
an object no content keeps (abandoned before registration; unregistered
bytes escape hard forget). ingest_stored's refusal path uses it. The
changelog gets an Unreleased section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
@fazpu
fazpu force-pushed the feat/ingest-stored-discard-refused branch from dca26b0 to 78ad589 Compare November 7, 2026 16:04
@fazpu
fazpu merged commit 54ba0f2 into main Nov 7, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant